package com.tnovoselec.android.orm.db;

import com.j256.ormlite.db.BaseSqliteDatabaseType;
import com.j256.ormlite.field.DataPersister;
import com.j256.ormlite.field.FieldConverter;
import com.j256.ormlite.field.types.DateStringType;


public class SqliteAndroidDatabaseType extends BaseSqliteDatabaseType {

	public SqliteAndroidDatabaseType() {
		super();
	}

	@Override
	public void loadDriver() {
		// DO nothing
	}

	@Override
	public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
		return true;
	}

	@Override
	protected String getDriverClassName() {
		return null;
	}

	@Override
	public String getDatabaseName() {
		return "Android SQLite";
	}

	@Override
	protected void appendDateType(StringBuilder sb, int fieldWidth) {
		// Default is to store the date as a String.
		super.appendStringType(sb, fieldWidth);
	}

	@Override
	protected void appendBooleanType(StringBuilder sb, int fieldWidth) {
		// We have to convert booleans to numbers.
		super.appendShortType(sb, fieldWidth);
	}

	@Override
	public FieldConverter getFieldConverter(DataPersister dataPersister) {
		// We are only overriding certain types.
		switch (dataPersister.getSqlType()) {
			case DATE:
				return DateStringType.getSingleton();
			default:
				return super.getFieldConverter(dataPersister);
		}
	}

	@Override
	public boolean isNestedSavePointsSupported() {
		return false;
	}

	@Override
	public boolean isBatchUseTransaction() {
		return true;
	}
}
